<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../css/new.css">
	</head>
	<body>
		<div class="mui-content" id="page">
			<div class="p-mw login">
				<img class="p-mw" src="../img/login.png">
				<div class="p-posr loginBox">
					<form class="mui-input-group">
						<div class="p-mw login_tag">
							<span @click="login4A($event,1)">内部登录</span>
							<span class="active" @click="login4A($event,0)">外部登录</span>
						</div>
					    <div class="mui-input-row">
							<input type="text" v-model="form.phone" placeholder="请输入手机号">
					    </div>
					    <div class="mui-input-row">
					        <input type="password" class="mui-input-password" v-model="form.password" placeholder="请输入密码">
							
						</div>
						<div class="mui-input-row">
						    <input type="text" v-model="form.code" placeholder="请输入验证码">
							<button type="button" @click="sendCode" class="mui-btn">{{btnTxt}}</button>
						</div>
					    <div class=" p-btn" @click="login">登录</div>
						<div class="p-mw p-posa p-btn" v-if="isOffLine" @click="offlineLoginMqms" style="color:#014B86; 35px;background: #b0d6fb;" >检修离线登录</div>
						
					</form>
					
				</div>
				<!-- end loginBox -->
				<div >
					<div style="text-align: center;margin-top: 35px;font-size: 12px;color: #014B86;" class="curbbh"></div>
				</div>
				
				<div class="p-mw p-posa loginBar">
					<span @click="reg">注册</span>
					<!--
					<span @click="deji">入场登记</span>
					-->
					<span @click="restpass">找回密码</span>
				</div>
			</div><!-- end login -->
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/jquery-3.2.1.min.js"></script>
		<script src="../js/mkeyplus.base.js?1"></script>
		<script src="../../../js/common.js"></script>
		<script type="text/javascript" src="../../../js/vue.js"></script>
		<script src="js/md5.js"></script>
		<script src="js/api.js"></script>
		<script src="js/OAuthPlugin.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/appUpdate.js"></script>
	<script>
		mui.init();
		var first = null;
		var htapi = new HTGlobal();
		var page = new Vue({
			  el: '#page',
			  data: {
				  form:{
					phone:'',
					password:'',
					code:''
				  },
				  inputType:'password',
				  btnTxt:'发送验证码',
				  curtype:3,
				  isOffLine: localStorage.getItem('mqmsToken') !== null ? true : false
			  },
			  methods:{
				  login(){
					  var _th = this;
					  //登录
					  if (_th.form.phone == "") {
					    mui.toast('请输入手机号!');
					    return;
					  }
					  if(!(/^1[3456789]\d{9}$/.test(_th.form.phone))){
					  	mui.toast('手机号码输入错误！');
					  	return false;
					  }
					  if (_th.form.password == "") {
					    mui.toast('请输入密码!');
					    return;
					  }
					  if(_th.form.code==''){
						  mui.toast('请输入验证码！');
						  return;
					  }
					  
					  // if(!(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,18}$/.test(_th.form.password))){
					  if(!/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W_]).{12,}/.test(_th.form.password)){
						  mui.alert('您的登录密码是弱密码，请通过找回密码修改后再登录使用', '系统提示', function() {
						          page.restpass()
						   });
						  return;
					  }
					  
					  var post_data = JSON.parse(JSON.stringify(_th.form));
					  post_data.password = md5(post_data.password);
					  htapi.outsidersLogin(post_data,function(res){
						  if(res.code!='0'){
						  	mui.toast(res.msg);
						  	return false;
						  }else{
							  localStorage.setItem("token", res.data.token);
							  htapi.fetch({appUserId:res.data.id,projectId:res.data.currentProjectId,
							  enterpriseProjectId:res.data.enterpriseProjectId},function(data){
									//console.log(JSON.stringify(data));
									//return;
									res.data.notice = 1;
									if(data.code=='0'){
										var _data = data.data;
										if(!_data.id){
											res.data.notice = 0;
										}
									}
									delete res.data.password;
									localStorage.setItem('outUserId', res.data.id);
									localStorage.setItem("outUser", JSON.stringify(res.data));
									//跳转
									mui.openWindow({
									  url: '../home.html',
									  id: 'home.html',
									});
									console.log('登录成功');
									setTimeout(function(){
										plus.webview.currentWebview().close('none')
									},1000)
			
							  },false,'findAdmissionNotice','post')

						  }
					  });
				  },
				  reg(){
					  //前往注册
					  mui.openWindow({
					    url: './register.html',
					    id: 'register.html',
					  });
				  },
				  deji(){
					  //前往登记记录
					  mui.openWindow({
					    url: './registration.html',
					    id: 'registration.html',
					  });
				  },
				  restpass(){
					  //忘记密码
					  mui.openWindow({
					    url: './retrieve_pass.html',
					    id: 'retrieve_pass.html',
					  });
				  },
				  changeInputType(){
					  //显示与关闭显示
					  this.inputType = this.inputType=='text'?'password':'text';
				  },
				  sendCode(){
				  	//发送验证码
				  	htapi.sendCode(this.$data);
					//htapi.sendMsgCode(this.$data,'verificationCode2')
				  },
				  // 4A单点登录
				  login4A(e,n){
					  console.log(this.curtype);
					  
					  if(this.curtype == 1){
						  var btnArray = ['取消', '确定'];
						  mui.confirm('当前无网络，是否离线登录？', '提示', btnArray, function(e) {
						    if (e.index == 1) { 
						     console.log('离线登录');
							 mui.openWindow({
							   url: '../group_home.html',
							   id: 'home.html',
							   show:{
							 	  aniShow:'none'
							   }
							 });
						    }
						  })
					  }else{
						  var pe = $(e.target).parent();
						  pe.find('span').removeClass('active');
						  $(e.target).addClass('active');
						  if(n==1){
						  	setTimeout(function(){
						  		pe.find('span').removeClass('active').eq(1).addClass('active');
						  	},1000);
						  	htapi.toOAuth();
						  }
					  }
					
				  },
				  // 离线登录检修质量
				  offlineLoginMqms(){
					// localStorage.removeItem('mqmsToken')
					if(localStorage.getItem('mqmsToken') == null){
						mui.toast('无离线用户数据，网络状态正常下请先外部登录进入检修质量');
						return
					}
					var btnArray = ['取消', '确定'];
					mui.confirm('当前无网络，是否离线登录？', '提示', btnArray, function(e) {
						if (e.index == 1) { 
						 console.log('离线登录');
						 mui.openWindow({
						   url: '../../mqms/index.html',
						   id: 'index.html',
						   show:{
							  aniShow:'none'
						   }
						 });
						}
					})
				  }
			  },
			  created(){
				localStorage.removeItem('fromNotice')
			  }
		});
	mui.plusReady(function () {
		page.curtype = plus.networkinfo.getCurrentType();
	    _AppUpdate.initUpdate(function(){console.log('更新完成！')});
		
		plus.runtime.getProperty(plus.runtime.appid, function(info) {
			console.log('版本号' + info.version)
			document.querySelector('.curbbh').innerText = '当前版本:' + info.version
		})
	})
    mui.back = function() {
      //首次按键，提示‘再按一次退出应用’
      if (!first) {
        first = new Date().getTime();
        mui.toast('再按一次退出应用');
        setTimeout(function() {
          first = null;
        }, 800);
      } else {
        if (new Date().getTime() - first < 1000) {
          plus.runtime.quit();
        }
      }
    }		
	</script>		
	</body>
</html>
